﻿/************************************************
* Copyright (C) 2011 东北农业大学(NEAU) 版权所有。
* 文件名：  cms.js
* 版本号：  1.0
* 功能描述：cms extjs 布局
* 作者：    徐永明
* 创建日期: 2011-06-27
* 修改人：
* 修改日期：
* 修改描述：
************************************************/
Ext.BLANK_IMAGE_URL = '/script/ext/resources/images/s.gif';
var siteid = "0";
Ext.onReady(function () {
    function GetDepmetName(depmetId) {
        var str = Jxym.ajax.request("server/User/DepmetGetModel.aspx?depmetId=" + depmetId);
        var json = Ext.util.JSON.decode(str);
        return json.Name;
    }
    /*延时加载*/
    setTimeout(function () { Ext.get('loading').remove(); Ext.get('loading-mask').fadeOut({ remove: true }); }, 400);
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = "qtip";

    /*专题列表*/
    var SiteList = new Ext.form.ComboBox({
        anchor: '100%',
        fieldLabel: "选择专题",
        emptyText: "请选择专题",
        listEmptyText: "*暂无专题信息*",
        blankText: '请选择专题',
        triggerAction: 'all',
        forceSelection: true,
        editable: false,
        mode: 'remote',
        valueField: 'did',
        displayField: 'dname',
        store: new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({ url: "server/sites.aspx" }),
            reader: new Ext.data.JsonReader({}, [{ name: 'did', type: 'string', mapping: "Name" }, { name: 'dname', type: 'string', mapping: "Title"}]),
            autoLoad: true
        })
    });
    /*布局（南部）*/
    var north = new Ext.form.FormPanel({
        height: 35,
        region: 'north',
        margins: '5 5 0 5',
        labelAlign: "right",
        labelWidth: 60,
        bodyStyle: "padding:5px;",
        items: [SiteList]
    });
    var treeDataLoader = new Ext.tree.TreeLoader({ dataUrl: 'server/Cms_ContentClass.aspx'/*, folderSort: true, property: 'text'*/ });
    /*创建根节点*/
    var TreeRoot = new Ext.tree.AsyncTreeNode({ text: '根节点', id: 'TreeRoot', expanded: true, leaf: false });
    /*创建树面板*/
    var Tree = new Ext.tree.TreePanel({
        id: 'Tree',
        region: 'west',
        width: 138,
        minSize: 138,
        margins: '5 0 0 5',
        cmargins: '5 5 0 5',
        bodyStyle: "padding:2px;",
        loader: treeDataLoader,
        title: "专题栏目",
        split: true,
        rootVisible: true,
        lines: true,
        autoScroll: true,
        enableDD: true, //是否支持拖拽效果false
        animate: true,
        collapsible: true,
        containerScroll: true,
        root: TreeRoot
    });
    // 树形编辑器
    var treeEditor = new Ext.tree.TreeEditor(Ext.getCmp('Tree'), {
        id: 'tree-Manage',
        allowBlank: false
    }, {
        listeners: {
            'complete': function (edit, value, startValue) {
                var pn = edit.editNode.parentNode;
                if (pn) {
                    if (value != startValue) {
                        var id = edit.editNode.id.indexOf('xnode') >= 0 ? 0 : edit.editNode.id;
                        var parentid = pn.id == 'TreeRoot' ? 0 : pn.id;
                        var params = { ID: id, ParentID: parentid, Title: value, siteName: SiteList.getValue() };
                        Ext.Ajax.request({
                            url: "server/ContentClassAdd.aspx",
                            method: 'POST',
                            params: params,
                            success: function (response) {
                                var json = Ext.util.JSON.decode(response.responseText);
                                if (json.success) {
                                    if (json.identity) {
                                        edit.editNode.id = json.identity;
                                    }
                                } else {
                                    Ext.Msg.alert("错误", json.msg);
                                }
                            }
                        });
                    }
                }
            }
        }
    });
    //给tree添加事件
    Tree.on('rightClickCont', Tree.rightClick, Tree);
    // 定义右键菜单
    var rightClick = new Ext.menu.Menu({
        id: 'rightClickCont',
        items: [{
            iconCls: 'icon-expand-all',
            text: '全部展开',
            tooltip: '全部展开',
            handler: function () { TreeRoot.expand(true); }
        }, {
            iconCls: 'icon-collapse-all',
            text: '全部折叠',
            tooltip: '全部折叠',
            handler: function () { TreeRoot.collapse(true); }
        }, '-', {
            iconCls: 'icon-add-t',
            id: 'insertNode',
            text: '添加同级目录',
            tooltip: '添加同级目录',
            handler: function (tree) {
                var selectedNode = Tree.getSelectionModel().getSelectedNode();
                var selectedParentNode = selectedNode.parentNode;
                var newNode = new Ext.tree.TreeNode({
                    text: '新建节点' + selectedNode.id
                });
                if (selectedParentNode == null) {
                    selectedNode.appendChild(newNode);
                } else {
                    selectedParentNode.appendChild(newNode);
                }
                setTimeout(function () {
                    treeEditor.editNode = newNode;
                    treeEditor.startEdit(newNode.ui.textNode);
                }, 10);
            }
        }, {
            iconCls: 'icon-add-z',
            id: 'appendNode',
            text: '添加子目录',
            tooltip: '添加子目录',
            handler: function (tree) {
                var selectedNode = Tree.getSelectionModel().getSelectedNode();
                if (selectedNode.isLeaf()) {
                    selectedNode.leaf = false;
                }
                var newNode = selectedNode.appendChild(new Ext.tree.TreeNode({
                    text: '新建节点' + selectedNode.id
                }));
                newNode.parentNode.expand(true, true, function () {
                    setTimeout(function () {
                        treeEditor.editNode = newNode;
                        treeEditor.startEdit(newNode.ui.textNode);
                    }, 10);
                });
            }
        }, {
            id: 'cmenu_del',
            iconCls: 'icon-del',
            tooltip: '删除',
            id: 'delNode',
            text: '删除',
            handler: function (tree) {
                var selectedNode = Tree.getSelectionModel().getSelectedNode();
                if (selectedNode.id != "TreeRoot") {
                    Ext.Ajax.request({
                        url: "server/ContentClassDel.aspx",
                        method: 'POST',
                        params: { id: selectedNode.id },
                        success: function (response) {
                            var json = Ext.util.JSON.decode(response.responseText);
                            if (json.success) {
                                selectedNode.remove();
                                Ext.Msg.alert("提示", json.msg);
                            } else {
                                Ext.Msg.alert("错误", json.msg);
                            }
                        }
                    });
                } else {
                    Ext.Msg.alert("提示信息", "不能删除根节点");
                }
            }
        }, {
            id: 'cmenu_edit',
            iconCls: 'icon-edit',
            tooltip: '编辑',
            id: 'modifNode',
            text: '编辑',
            handler: function () {
                var selectedNode = Tree.getSelectionModel().getSelectedNode();
                if (selectedNode.id != "TreeRoot") {
                    treeEditor.editNode = selectedNode;
                    treeEditor.startEdit(selectedNode.ui.textNode);
                } else {
                    Ext.Msg.alert("提示信息", "不支持编辑根节点");
                }
            }
        }]
    });

    // 增加右键弹出事件
    Tree.on('contextmenu', function (node, event) {
        var ContentClass = ClassForm.getForm().findField("ContentClassID");
        if (ContentClass.getValue() != "0") {
            //声明菜单类型
            event.preventDefault(); //这行是必须的，使用preventDefault方法可防止浏览器的默认事件操作发生。
            node.select();
            if (node.id == "TreeRoot") {
                rightClick.items.get(0).show();
                rightClick.items.get(1).show();
                rightClick.items.get(2).hide();
                rightClick.items.get(3).hide();
                rightClick.items.get(4).show();
                rightClick.items.get(5).hide();
                rightClick.items.get(6).hide();
            } else {
                rightClick.items.get(0).hide();
                rightClick.items.get(1).hide();
                rightClick.items.get(2).hide();
                rightClick.items.get(3).show();
                rightClick.items.get(4).show();
                rightClick.items.get(5).show();
                rightClick.items.get(6).show();
            }
            rightClick.showAt(event.getXY()); // 取得鼠标点击坐标，展示菜单
        } else {
            Ext.Msg.alert("提示信息", "请选择专题和栏目分类");
        }
    });
    /**/
    Tree.on('dblclick', function (node, e) {
        if (node) {
            grid.setTitle(SiteList.getRawValue() + " - " + node.text + "[" + node.id + "] - 信息列表");
            ClassForm.setTitle(SiteList.getRawValue() + " - " + node.text + "[" + node.id + "] - 信息添加");
            ClassForm.getForm().findField("ContentClassID").setValue(node.id);
            Ext.getCmp("saveBtn").setText("确认添加");
            groupStore.load({ params: { start: 0, limit: pageSize, classid: node.id} });
            document.getElementById("classid").value = node.id;
        }
    });
    Tree.on('beforemovenode', function (tree, node, oldNode, newNode, index) {
        var r = true;
        var _odlIndex = oldNode.indexOf(node);
        if ((oldNode.id == newNode.id) && (_odlIndex == index)) {
            r = false;
        }
        if (r) {
            Ext.Ajax.request({
                url: 'server/Cms_ContentClassSort.aspx',
                method: 'post',
                params: { nodeId: node.id, oldNodeId: oldNode.id, newNodeId: newNode.id, index: index },
                success: function (response, option) {
                    var result = response.responseText;
                }
            });
        }
    });
    SiteList.on("select", function (combo, record, index) {
        treeDataLoader.baseParams = { siteName: combo.getValue() };
        treeDataLoader.load(TreeRoot);
        siteid = combo.getValue();
        grid.setTitle(combo.getRawValue());
    });
    /*定义请求参数*/
    var proxy = new Ext.data.HttpProxy({ url: "server/contentList.aspx" });
    //*定义数据模型*/
    var ContentInfo = new Ext.data.Record.create([
                        { name: 'ID', type: 'int', mappging: "ID" },
                        { name: 'Title', type: 'string', mappging: "Title" },
                        { name: 'MYURL', type: 'string', mappging: "MYURL" },
                        { name: 'Html', type: 'string', mappging: "Html" },
                        { name: 'FileName', type: 'string', mappging: "FileName" },
                        { name: 'VideoFileName', type: 'string', mappging: "VideoFileName" },
                        { name: 'ViewPhoto', type: 'string', mappging: "ViewPhoto" },
                        { name: 'ContentTypeID', type: 'int', mappging: "ContentClassID" },
                        { name: 'AddUser', type: 'string', mappging: "AddUser" },
                        { name: 'AddTime', type: 'date', mappging: "AddTime" },
                        { name: 'UpUser', type: 'string', mappging: "UpUser" },
                        { name: 'ContentClassID', type: 'int', mappging: "ContentClassID" },
                        { name: 'UpTime', type: 'date', mappging: "UpTime" },
                        { name: 'FromW', type: 'string', mappging: "FromW" },
                        { name: 'BigIm', type: 'string', mappging: "BigIm" }
                        ]);
    /*创建阅读器*/
    var reader = new Ext.data.JsonReader({ totalProperty: "Count", root: "List" }, ContentInfo);
    var formReader = new Ext.data.JsonReader({}, ContentInfo);
    /*创建数据源*/
    var groupStore = new Ext.data.GroupingStore({
        proxy: proxy,
        reader: reader,
        sortInfo: { field: 'ID', direction: 'DESC' }
    });
    groupStore.on('beforeload', function (thiz, options) {
        Ext.apply(this.baseParams, { classid: document.getElementById("classid").value });
    });

    /*设置每页条数*/
    var pageSize = 5;
    var cookiePageSize = parseInt(Ext.util.Cookies.get("pageSize"));
    if (cookiePageSize) { pageSize = cookiePageSize; }
    /*加载数据源*/
    groupStore.load({ params: { start: 0, limit: pageSize} });
    /*创建选择列模型*/
    var sm = new Ext.grid.CheckboxSelectionModel();
    /*定义列模型*/
    var cm = new Ext.grid.ColumnModel([
            new Ext.grid.RowNumberer(),
            sm,
            { id: 'ID', header: '编号', dataIndex: 'ID', width: 50, sortable: true, resizable: false, hideable: false, menuDisabled: true },
            { id: 'Title', header: '标题', dataIndex: 'Title', width: 100, hideable: false, sortable: true },
            { id: 'Html', header: 'Html内容', dataIndex: 'Html', width: 100, hideable: false, hidden: true, sortable: true },
            { id: 'FileName', header: '附件', dataIndex: 'FileName', width: 70, sortable: true, hidden: true },
            { id: 'VideoFileName', header: '相关视频', dataIndex: 'VideoFileName', width: 70, sortable: true, hidden: true },
            { id: 'ViewPhoto', header: '预览图', dataIndex: 'ViewPhoto', width: 70, sortable: true, hidden: true },
            { id: 'ContentTypeID', header: '信息类型', dataIndex: 'ContentTypeID', width: 90, sortable: true },
            { id: 'MYURL', header: 'URL', dataIndex: 'MYURL', width: 82 },
            { id: 'AddUser', header: '添加人', dataIndex: 'AddUser', width: 70, sortable: true, hidden: true },
            { id: 'AddTime', header: '添加时间', dataIndex: 'AddTime', width: 80, sortable: true, renderer: Ext.util.Format.dateRenderer('Y-m-d'), hidden: true },
            { id: 'UpUser', header: '最后编辑', dataIndex: 'UpUser', width: 82, sortable: true },
            { id: 'UpTime', header: '编辑时间', dataIndex: 'UpTime', width: 82, sortable: true, renderer: Ext.util.Format.dateRenderer('Y-m-d') },
            { id: 'ContentClassID', header: '分类', dataIndex: 'ContentClassID', hidden: true },
            { id: 'FromW', header: '图片来源', dataIndex: 'FromW', width: 70, sortable: true, hidden: true },
            { id: 'BigIm', header: '大图', dataIndex: 'BigIm', width: 70, sortable: true, hidden: true }
            ]);

    var grid = new Ext.grid.GridPanel({
        title: "信息列表",
        store: groupStore,
        border: true,
        margins: '5 5 0 0',
        region: 'center',
        autoExpandColumn: "Title",
        loadMask: { msg: '正在努力的加载，请稍等片刻..' },
        view: new Ext.grid.GroupingView(),
        sm: sm,
        cm: cm,
        tbar: [{
            iconCls: 'icon-user_add-16',
            tooltip: '添加',
            text: '添加',
            handler: function (btn) {
                var ContentClass = ClassForm.getForm().findField("ContentClassID");
                if (ContentClass.getValue() != "0") {
                    ClassForm.expand();
                    Ext.getCmp("saveBtn").setText("确认添加");
                    var ft = ClassForm.title;
                    ClassForm.setTitle(ft.replace("编辑", "添加"));
                    var classId = ContentClass.getValue();
                    ClassForm.getForm().reset();
                    ContentClass.setValue(classId);
                } else {
                    Ext.Msg.alert("提示信息", "请选择专题和栏目分类");
                }
            }
        }, {
            ref: '../editBtn',
            iconCls: 'icon-edit',
            tooltip: '编辑',
            text: '编辑',
            disabled: true,
            handler: function () {
                var selectNode = grid.getSelectionModel().getSelections();
                ClassForm.expand();
                if (selectNode) {
                    var row = selectNode[0];
                    Ext.getCmp("saveBtn").setText("确认更新");
                    var ft = ClassForm.title;
                    ClassForm.setTitle(ft.replace("添加", "编辑"));
                    ClassForm.getForm().loadRecord(row);
                    ClassForm.doLayout();
                }
            }
        }, {
            ref: '../removeBtn',
            iconCls: 'icon-user_delete-16',
            tooltip: '删除',
            text: '删除',
            disabled: true,
            handler: function () {
                Ext.MessageBox.confirm("确认提示", "确认要删除所选行数据？", function (btn) {
                    if (btn == "yes") {
                        var s = grid.getSelectionModel().getSelections();
                        var delR = new Array();
                        var delRid = new Array();
                        for (var i = s.length - 1; i >= 0; i--) {
                            var r = s[i];
                            if (r.get('ID') != undefined) { delRid.push(r.get('ID')); delR.push(r); }
                        }
                        Ext.Ajax.request({
                            url: "SERVER/ContentDel.aspx",
                            method: 'POST',
                            params: { id: delRid },
                            success: function (response) {
                                var json = Ext.util.JSON.decode(response.responseText);
                                if (json.success) {
                                    for (var i = 0; i < delR.length; i++) {
                                        if (json.ids.valueOf(delR[i].get('ID'))) { groupStore.remove(delR[i]) }
                                    }
                                    Ext.Msg.alert("提示", "已删除" + json.count + "行<br/>" + json.msg);
                                } else {
                                    Ext.Msg.alert("错误", json.msg);
                                }
                            }
                        });
                    }
                });
            }
        }],
        bbar: new Ext.PagingToolbar({
            store: groupStore,
            pageSize: pageSize,
            displayInfo: true,
            prependButtons: true,
            displayMsg: "本页显示第{0}条到第{1}条数据，共{2}条",
            emptyMsg: "暂无记录"
        })
    });

    var ContentType = new Ext.form.ComboBox({
        name: "ContentTypeID",
        anchor: '100%',
        fieldLabel: "信息类型",
        labelStyle: 'color:red',
        emptyText: "请选择信息类型",
        listEmptyText: "*暂无信息类型",
        blankText: '请选择信息类型',
        hiddenName: "ContentTypeID",
        triggerAction: 'all',
        forceSelection: true,
        allowBlank: false, //不允许为空
        editable: false,
        blankText: '信息类型不能为空', //不允许为空给的提示
        mode: 'remote',
        valueField: 'did',
        displayField: 'dname',
        store: new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({ url: "SERVER/contentType.aspx" }),
            reader: new Ext.data.JsonReader({}, [{ name: 'did', type: 'int', mapping: "ID" }, { name: 'dname', type: 'string', mapping: "Title"}]),
            autoLoad: true
        })
    });

    var fckeditor1 = new Ext.form.FCKeditor({
        fieldLabel: '信息内容',
        toolbar: 'Default',
        height: '100%',
        //hidden: true,
        id: 'fckeditor1',
        hiddenName: "Html",
        name: "Html"
    });
    var videoFileName = new Ext.ux.form.FileUploadField({
        hiddenName: "VideoFileName",
        name: 'VideoFileName',
        anchor: '100%',
        filter: '图片|*.jpg',
        emptyText: '请选择相关视频文件',
        fieldLabel: '相关视频',
        buttonText: '',
        buttonCfg: { iconCls: 'icon-vcard_add' }
    });
    var FileName = new Ext.ux.form.FileUploadField({
        hiddenName: "FileName",
        name: 'FileName',
        anchor: '100%',
        msgTarget: 'side',
        emptyText: '请选择附件文件',
        fieldLabel: '附件文件',
        buttonText: '',
        buttonCfg: { iconCls: 'icon-vcard_add' }
    });
    var ViewPhoto = new Ext.ux.form.FileUploadField({
        hiddenName: "ViewPhoto",
        name: 'ViewPhoto',
        anchor: '100%',
        emptyText: '请选择预览图文件',
        fieldLabel: '预览图',
        buttonText: '',
        buttonCfg: { iconCls: 'icon-picture_add' }
    });
    var BigIm = new Ext.ux.form.FileUploadField({
        hiddenName: "BigIm",
        name: 'BigIm',
        anchor: '100%',
        emptyText: '请选择大图',
        fieldLabel: '大图',
        buttonText: '',
        buttonCfg: { iconCls: 'icon-picture_add' }
    });
    var FromW = new Ext.form.TextField({
        fieldLabel: '信息来源',
        name: 'FromW',
        value: '图片来自互联网',
        anchor: '100%'
    });
    var URL = new Ext.form.TextField({
        fieldLabel: 'URL地址',
        name: 'MYURL',
        value: 'http://',
        anchor: '100%'
    })
    var ClassForm = new Ext.form.FormPanel({
        region: 'south',
        title: "编辑信息",
        margins: '0 5 5 5',
        split: true,
        collapsible: true,
        frame: true,
        height: 400,
        labelAlign: "right",
        labelWidth: 55,
        buttonAlign: "center",
        bodyStyle: "padding:10px 5px;",
        border: true,
        items: [new Ext.form.Hidden({ ID: 'ID', value: 0, name: 'ID' }),
                new Ext.form.Hidden({ ID: 'ContentClassID', value: 0, name: 'ContentClassID' }), {
                    layout: 'column',
                    items: [{
                        columnWidth: .3,
                        layout: 'form',
                        items: [{
                            xtype: 'textfield',
                            fieldLabel: '信息标题',
                            labelStyle: 'color:red',
                            minLength: 1,
                            minLengthText: "长度不能小于1个字符",
                            maxLength: 100,
                            maxLengthText: "长度超过了100个字符",
                            name: 'Title',
                            allowBlank: false,
                            blankText: '信息标题不能为空',
                            anchor: '100%'
                        }]
                    }, {
                        columnWidth: .2,
                        layout: 'form',
                        items: [ContentType]
                    }, {
                        columnWidth: .3,
                        layout: 'form',
                        items: [FileName]
                    }, {
                        columnWidth: .2,
                        layout: 'form',
                        items: [{
                            xtype: 'datefield',
                            fieldLabel: '添加时间',
                            labelStyle: 'color:red',
                            name: 'AddTime',
                            allowBlank: false,
                            editable: false,
                            blankText: '添加时间不能为空',
                            anchor: '100%',
                            format: "Y-m-d",
                            value: new Date()
                        }]
                    }]
                }, {
                    layout: 'column',
                    items: [{
                        columnWidth: .3,
                        layout: 'form',
                        items: [videoFileName]
                    }, {
                        columnWidth: .2,
                        layout: 'form',
                        items: [URL]
                    }, {
                        columnWidth: .3,
                        layout: 'form',
                        items: [ViewPhoto]
                    }, {
                        columnWidth: .2,
                        layout: 'form',
                        items: [{
                            xtype: 'datefield',
                            fieldLabel: '更新时间',
                            labelStyle: 'color:red',
                            name: 'UpTime',
                            allowBlank: false,
                            editable: false,
                            blankText: '更新时间不能为空',
                            anchor: '100%',
                            format: "Y-m-d",
                            value: new Date()
                        }]
                    }]
                }, {
                    layout: 'column',
                    items: [{
                        columnWidth: .3,
                        layout: 'form',
                        items: [BigIm]
                    }, {
                        columnWidth: .2,
                        layout: 'form',
                        items: [FromW]
                    }]
                }, fckeditor1],
        fileUpload: true,
        buttons: [{
            id: "saveBtn",
            text: "确认添加",
            handler: function () {
                if (ClassForm.getForm().findField("ContentClassID").getValue() == "0") {
                    Ext.Msg.alert("提示", "请选择专题和栏目分类");
                    return false;
                }
                if (ClassForm.getForm().isValid()) {
                    if (ContentType.getRawValue() == "HTML内容") {
                        if (fckeditor1.getHtml() == "") {
                            Ext.Msg.alert("提示", "信息内容不能为空"); return false;
                        }
                    }
                    if (ContentType.getRawValue() == "URL（链接）") {
                        if (URL.getValue() == "http://" || URL.getValue() == "") {
                            Ext.Msg.alert("提示", "请输入URL链接地址"); return false;
                        }
                    }
                    if (ContentType.getRawValue() != "HTML内容" && ContentType.getRawValue() != "URL（链接）") {
                        if (FileName.getValue() == "" || FileName.getValue() == "no.jpg" || FileName.getValue() == undefined) {
                            Ext.Msg.alert("提示", "请选择附件文件:" + ContentType.getRawValue()); return false;
                        }
                    }
                    ClassForm.getForm().submit({
                        params: { Html1: fckeditor1.getHtml(), siteid: siteid },
                        submitEmptyText: false,
                        url: 'server/ContentAdd.aspx',
                        waitTitle: '操作提示',
                        waitMsg: '正在处理数据，请稍后...',
                        success: function (form, action) {
                            Ext.Msg.alert("请求成功", action.result.msg, function () {
                                ClassForm.getForm().reset();
                                groupStore.reload();
                            });
                        }, failure: function (form, action) {
                            Ext.Msg.alert("请求失败", action.result.msg);
                        }
                    });
                }
            }
        }, {
            text: "重置",
            handler: function () {
                ClassForm.getForm().reset();
            }
        }]
    });
    ContentType.on('select', function (combo, record, index) {
        //        if (combo.getRawValue() == "HTML内容") {
        //            fckeditor1.show();
        //        } else {
        //            fckeditor1.hide();
        //        }
    });

    //创建页面布局 
    var viewport = new Ext.Viewport({ layout: 'border', items: [north, Tree, grid, ClassForm] });
    ClassForm.collapse();
    viewport.doLayout();
    //有选择行启用删除按钮
    grid.getSelectionModel().on('selectionchange', function (sm) {
        grid.removeBtn.setDisabled(sm.getCount() < 1);
        grid.editBtn.setDisabled(sm.getCount() != 1);
    });
    grid.on('rowdblclick', function (g, index, e) {
        ClassForm.expand();
        Ext.getCmp("saveBtn").setText("确认更新");
        var ft = ClassForm.title;
        ClassForm.setTitle(ft.replace("添加", "编辑"));
        var r = g.getSelectionModel().getSelected();
        ClassForm.getForm().loadRecord(r);
        ClassForm.doLayout();
    });
});